/**
 * 
 */
package ai

import java.util.List

import data.Player
import data.Position
import data.Team
import data.Data.PlayerState
import data.Data.Race
import data.Data.Role
import data.Data.TeamID
import engine.IGameEngine
import engine.Pitch
import engine.GameEngine.GameState
import exception.BadPositionException
import exception.IllegalPlacementException

/**
 * Fake game engine implementation.
 * 
 * @author Tomasz Dąbrowski
 *
 */
class GameEngineFake implements IGameEngine {
	List<Team> teams
	Team currentTeam
	GameState gameState = GameState.KICKING_TEAM
	Pitch playingField

	public GameEngineFake() {
		teams = [new Team(), new Team()]
		teams[0].setId(TeamID.TEAM_A)
		teams[1].setId(TeamID.TEAM_B)
		List numbers = 1..11
		List roles = ([
			Role.CATCHER,
			Role.CATCHER,
			Role.THROWER,
			Role.THROWER,
			Role.BLITZER]
		+ (1..6).collect { Role.LINEMAN })
		assert numbers.size() == roles.size()
		teams.eachWithIndex { Team team, int index ->
			List teamRoles = roles.collect { it }
			assert !teamRoles.isEmpty()
			numbers.each { int number ->
				number = number + (index * 20)
				Player p = new Player("Player ${team.id}:${number}", Race.HUMAN, teamRoles.remove(0), number)
				p.setState(PlayerState.IN_DUGOUT)
				team.addPlayer(p)
			}
		}
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#currentTeamID()
	 */
	@Override
	public TeamID currentTeamID() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#endTurn()
	 */
	@Override
	public void endTurn() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#isGameEnd()
	 */
	@Override
	public boolean isGameEnd() {
		// TODO Auto-generated method stub
		return false;
	}

	boolean checkForTouchDown(Player arg0) {
		false
	}

	boolean resolveThrowBall(Player arg0, Position arg1) {
		true
	}

	boolean processStandup(Player arg0) {
		true
	}

	boolean resolveBlock(Player arg0, Position arg1) {
		false
	}

	public void initPlayingField() {
		playingField = new Pitch(teamA(), teamB())
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#getPlayingField()
	 */
	@Override
	public Pitch getPlayingField() {
		playingField
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#placePlayer(data.Player, data.Position)
	 */
	@Override
	public void placePlayer(Player player, Position pos) throws IllegalPlacementException, BadPositionException {
		throw new UnsupportedOperationException()
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#teamA()
	 */
	@Override
	public Team teamA() {
		teams[0]
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#teamB()
	 */
	@Override
	public Team teamB() {
		teams[1]
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#currentTeam()
	 */
	@Override
	public Team currentTeam() {
		currentTeam
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#isUpdateLock()
	 */
	@Override
	public boolean isUpdateLock() {
		true
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#isExiting()
	 */
	@Override
	public boolean isExiting() {
		false
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#getGameState()
	 */
	@Override
	public GameState getGameState() {
		gameState
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#onTouchBack(data.Player)
	 */
	@Override
	public void onTouchBack(Player player) {
	}

	/* (non-Javadoc)
	 * @see engine.IGameEngine#movePlayer(data.Player, data.Position)
	 */
	@Override
	public boolean movePlayer(Player player, Position newPos) {
		true
	}
}
